
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1.provide/inject · Gary的小窝</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Gary">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-solarizedlight.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="2.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    写在前面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../leetcode/">
            
                <a href="../leetcode/">
            
                    
                    Leetcode之旅
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../leetcode/1.html">
            
                <a href="../leetcode/1.html">
            
                    
                    1.两数之和
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../leetcode/2.html">
            
                <a href="../leetcode/2.html">
            
                    
                    2.两数相加
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../leetcode/3.html">
            
                <a href="../leetcode/3.html">
            
                    
                    3.无重复字符的最长子串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../leetcode/4.html">
            
                <a href="../leetcode/4.html">
            
                    
                    4.寻找两个有序数组的中位数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../leetcode/6.html">
            
                <a href="../leetcode/6.html">
            
                    
                    6.Z字形变换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../leetcode/9.html">
            
                <a href="../leetcode/9.html">
            
                    
                    9.回文数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../leetcode/11.html">
            
                <a href="../leetcode/11.html">
            
                    
                    11.盛最多水的容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../leetcode/12.html">
            
                <a href="../leetcode/12.html">
            
                    
                    12.整数转罗马数字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../leetcode/13.html">
            
                <a href="../leetcode/13.html">
            
                    
                    13.罗马数字转整数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="../leetcode/14.html">
            
                <a href="../leetcode/14.html">
            
                    
                    14.最长公共前缀
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="../leetcode/322.html">
            
                <a href="../leetcode/322.html">
            
                    
                    322.零钱兑换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../leetcode/72.html">
            
                <a href="../leetcode/72.html">
            
                    
                    72.编辑距离
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../flutter/">
            
                <a href="../flutter/">
            
                    
                    Flutter从入门到放弃
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../flutter/dart1.html">
            
                <a href="../flutter/dart1.html">
            
                    
                    1.Dart语言(1)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../flutter/dart2.html">
            
                <a href="../flutter/dart2.html">
            
                    
                    2.Dart语言(2)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../flutter/widget1.html">
            
                <a href="../flutter/widget1.html">
            
                    
                    3.Flutter初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../flutter/containerText.html">
            
                <a href="../flutter/containerText.html">
            
                    
                    4.Container和Text组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../flutter/image.html">
            
                <a href="../flutter/image.html">
            
                    
                    5.Image组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../flutter/chapter2.html">
            
                <a href="../flutter/chapter2.html">
            
                    
                    6.Flutter 技术总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="./">
            
                <a href="./">
            
                    
                    Vue组件精讲
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.4.1" data-path="1.html">
            
                <a href="1.html">
            
                    
                    1.provide/inject
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="2.html">
            
                <a href="2.html">
            
                    
                    2.手动实现broadcast和dispatch方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../js/form.html">
            
                <a href="../js/form.html">
            
                    
                    3.自己动手实现带校验的Form表单组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../js/">
            
                <a href="../js/">
            
                    
                    JavaScript进阶
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../js/proxy.html">
            
                <a href="../js/proxy.html">
            
                    
                    1.Vue.js 3.0中的响应式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../js/el.html">
            
                <a href="../js/el.html">
            
                    
                    2.Element UI 源码初探
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../js/bind.html">
            
                <a href="../js/bind.html">
            
                    
                    3.bind的模拟实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../js/proto.html">
            
                <a href="../js/proto.html">
            
                    
                    4.JS原型和原型链
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../js/call.html">
            
                <a href="../js/call.html">
            
                    
                    5.模拟实现call和apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../js/ui.html">
            
                <a href="../js/ui.html">
            
                    
                    6.使用Vue cli3搭建组件库并发布到 npm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../js/microFE.html">
            
                <a href="../js/microFE.html">
            
                    
                    7.记一次基于qiankun的微前端的改造
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../js/git.html">
            
                <a href="../js/git.html">
            
                    
                    8.Git的使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../vueLibrary/">
            
                <a href="../vueLibrary/">
            
                    
                    基于Vue的PC端的组件库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../vueLibrary/1.html">
            
                <a href="../vueLibrary/1.html">
            
                    
                    1.环境搭建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../life/">
            
                <a href="../life/">
            
                    
                    网事杂谈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../life/1.html">
            
                <a href="../life/1.html">
            
                    
                    1.周杰伦专辑赏析--叶惠美
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../life/2.html">
            
                <a href="../life/2.html">
            
                    
                    2.周杰伦专辑赏析--七里香
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >1.provide/inject</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x4F7F;&#x7528;provideinject-&#x8FDB;&#x884C;&#x7EC4;&#x4EF6;&#x95F4;&#x901A;&#x4FE1;"><b></b>&#x4F7F;&#x7528;provide/inject &#x8FDB;&#x884C;&#x7EC4;&#x4EF6;&#x95F4;&#x901A;&#x4FE1;</a></li><ul><li><span class="title-icon "></span><a href="#&#x524D;&#x8A00;"><b></b>&#x524D;&#x8A00;</a></li><li><span class="title-icon "></span><a href="#&#x4EC0;&#x4E48;&#x662F;-provide--inject"><b></b>&#x4EC0;&#x4E48;&#x662F; provide / inject</a></li><li><span class="title-icon "></span><a href="#&#x66FF;&#x4EE3;-vuex"><b></b>&#x66FF;&#x4EE3; Vuex</a></li><li><span class="title-icon "></span><a href="#&#x4F7F;&#x7528;mixin"><b></b>&#x4F7F;&#x7528;mixin</a></li></ul></ul></div><a href="#&#x4F7F;&#x7528;provideinject-&#x8FDB;&#x884C;&#x7EC4;&#x4EF6;&#x95F4;&#x901A;&#x4FE1;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="&#x4F7F;&#x7528;provideinject-&#x8FDB;&#x884C;&#x7EC4;&#x4EF6;&#x95F4;&#x901A;&#x4FE1;"><a name="&#x4F7F;&#x7528;provideinject-&#x8FDB;&#x884C;&#x7EC4;&#x4EF6;&#x95F4;&#x901A;&#x4FE1;" class="anchor-navigation-ex-anchor" href="#&#x4F7F;&#x7528;provideinject-&#x8FDB;&#x884C;&#x7EC4;&#x4EF6;&#x95F4;&#x901A;&#x4FE1;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4F7F;&#x7528;provide/inject &#x8FDB;&#x884C;&#x7EC4;&#x4EF6;&#x95F4;&#x901A;&#x4FE1;</h1>
<h2 id="&#x524D;&#x8A00;"><a name="&#x524D;&#x8A00;" class="anchor-navigation-ex-anchor" href="#&#x524D;&#x8A00;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x524D;&#x8A00;</h2>
<p>&#x6211;&#x4EEC;&#x5047;&#x8BBE; &#x6709;&#x56DB;&#x4E2A;&#x7EC4;&#x4EF6;A B C D </p>
<p>A &#x548C; B&#x3001;B &#x548C; C&#x3001;B &#x548C; D &#x90FD;&#x662F;&#x7236;&#x5B50;&#x5173;&#x7CFB;&#xFF0C;C &#x548C; D &#x662F;&#x5144;&#x5F1F;&#x5173;&#x7CFB;&#xFF0C;A &#x548C; C &#x662F;&#x9694;&#x4EE3;&#x5173;&#x7CFB;&#xFF08;&#x53EF;&#x80FD;&#x9694;&#x591A;&#x4EE3;&#xFF09;&#x3002;&#x7EC4;&#x4EF6;&#x95F4;&#x7ECF;&#x5E38;&#x4F1A;&#x901A;&#x4FE1;&#xFF0C;Vue.js &#x5185;&#x7F6E;&#x7684;&#x901A;&#x4FE1;&#x624B;&#x6BB5;&#x4E00;&#x822C;&#x6709;&#x4E24;&#x79CD;&#xFF1A;</p>
<ul>
<li>ref&#xFF1A;&#x7ED9;&#x5143;&#x7D20;&#x6216;&#x7EC4;&#x4EF6;&#x6CE8;&#x518C;&#x5F15;&#x7528;&#x4FE1;&#x606F;&#xFF1B;</li>
<li>$$parent / $children&#xFF1A;&#x8BBF;&#x95EE;&#x7236; / &#x5B50;&#x5B9E;&#x4F8B;&#x3002;</li>
</ul>
<p>&#x8FD9;&#x4E24;&#x79CD;&#x90FD;&#x662F;&#x76F4;&#x63A5;&#x5F97;&#x5230;&#x7EC4;&#x4EF6;&#x5B9E;&#x4F8B;&#xFF0C;&#x4F7F;&#x7528;&#x540E;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x7EC4;&#x4EF6;&#x7684;&#x65B9;&#x6CD5;&#x6216;&#x8BBF;&#x95EE;&#x6570;&#x636E;&#xFF0C;&#x8FD9;&#x4E24;&#x79CD;&#x65B9;&#x6CD5;&#x7684;&#x5F0A;&#x7AEF;&#x662F;&#xFF0C;&#x65E0;&#x6CD5;&#x5728;&#x8DE8;&#x7EA7;&#x6216;&#x5144;&#x5F1F;&#x95F4;&#x901A;&#x4FE1;&#xFF0C;&#x90A3;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5C31;&#x5F97;&#x914D;&#x7F6E;&#x989D;&#x5916;&#x7684;&#x63D2;&#x4EF6;&#x6216;&#x5DE5;&#x5177;&#x4E86;&#xFF0C;&#x6BD4;&#x5982; Vuex &#x548C; Bus &#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#xFF0C;&#x8FD9;&#x91CC;&#x5C06;&#x4F1A;&#x4ECB;&#x7ECD;&#x53E6;&#x5916;&#x4E00;&#x79CD;&#x65B9;&#x6848;&#xFF0C;provide/inject</p>
<h2 id="&#x4EC0;&#x4E48;&#x662F;-provide--inject"><a name="&#x4EC0;&#x4E48;&#x662F;-provide--inject" class="anchor-navigation-ex-anchor" href="#&#x4EC0;&#x4E48;&#x662F;-provide--inject"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4EC0;&#x4E48;&#x662F; provide / inject</h2>
<p>&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;API Vue&#x7684;&#x7248;&#x672C;&#x5FC5;&#x987B;&#x5927;&#x4E8E;2.2.0,&#x5B83;&#x5728;<a href="https://cn.vuejs.org/v2/api/#provide-inject" target="_blank">&#x6587;&#x6863;</a>&#x4E2D;&#x8FD9;&#x6837;&#x4ECB;&#x7ECD; &#xFF1A;</p>
<blockquote>
<p>&#x8FD9;&#x5BF9;&#x9009;&#x9879;&#x9700;&#x8981;&#x4E00;&#x8D77;&#x4F7F;&#x7528;&#xFF0C;&#x4EE5;&#x5141;&#x8BB8;&#x4E00;&#x4E2A;&#x7956;&#x5148;&#x7EC4;&#x4EF6;&#x5411;&#x5176;&#x6240;&#x6709;&#x5B50;&#x5B59;&#x540E;&#x4EE3;&#x6CE8;&#x5165;&#x4E00;&#x4E2A;&#x4F9D;&#x8D56;&#xFF0C;&#x4E0D;&#x8BBA;&#x7EC4;&#x4EF6;&#x5C42;&#x6B21;&#x6709;&#x591A;&#x6DF1;&#xFF0C;&#x5E76;&#x5728;&#x8D77;&#x4E0A;&#x4E0B;&#x6E38;&#x5173;&#x7CFB;&#x6210;&#x7ACB;&#x7684;&#x65F6;&#x95F4;&#x91CC;&#x59CB;&#x7EC8;&#x751F;&#x6548;&#x3002;&#x5982;&#x679C;&#x4F60;&#x719F;&#x6089; React&#xFF0C;&#x8FD9;&#x4E0E; React &#x7684;&#x4E0A;&#x4E0B;&#x6587;&#x7279;&#x6027;&#x5F88;&#x76F8;&#x4F3C;&#x3002;</p>
</blockquote>
<p>&#x6211;&#x4EEC;&#x5148;&#x6765;&#x770B;&#x4E00;&#x4E0B;&#x8FD9;&#x4E2A; API &#x600E;&#x4E48;&#x7528;&#xFF0C;&#x5047;&#x8BBE;&#x6709;&#x4E24;&#x4E2A;&#x7EC4;&#x4EF6;&#xFF1A; A.vue &#x548C; B.vue&#xFF0C;B &#x662F; A &#x7684;&#x5B50;&#x7EC4;&#x4EF6;&#x3002;</p>
<pre class="language-"><code class="lang-js"><span class="token comment">// A.vue</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  provide<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    name<span class="token punctuation">:</span> <span class="token string">&apos;foo&apos;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// B.vue</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  inject<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&apos;name&apos;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token function">mounted</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>name<span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// Aresn</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x5728; A.vue &#x91CC;&#xFF0C;&#x6211;&#x4EEC;&#x8BBE;&#x7F6E;&#x4E86;&#x4E00;&#x4E2A; provide: name&#xFF0C;&#x503C;&#x4E3A; foo&#xFF0C;&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x5C31;&#x662F;&#x5C06; name &#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#x63D0;&#x4F9B;&#x7ED9;&#x5B83;&#x7684;&#x6240;&#x6709;&#x5B50;&#x7EC4;&#x4EF6;&#x3002;&#x800C;&#x5728; B.vue &#x4E2D;&#xFF0C;&#x901A;&#x8FC7; inject &#x6CE8;&#x5165;&#x4E86;&#x4ECE; A &#x7EC4;&#x4EF6;&#x4E2D;&#x63D0;&#x4F9B;&#x7684; name &#x53D8;&#x91CF;&#xFF0C;&#x90A3;&#x4E48;&#x5728;&#x7EC4;&#x4EF6; B &#x4E2D;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x901A;&#x8FC7; this.name &#x8BBF;&#x95EE;&#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#x4E86;&#xFF0C;&#x5B83;&#x7684;&#x503C;&#x4E5F;&#x662F; foo&#x3002;&#x8FD9;&#x5C31;&#x662F; provide / inject API &#x6700;&#x6838;&#x5FC3;&#x7684;&#x7528;&#x6CD5;&#x3002;</p>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF1A;</p>
<blockquote>
<p>provide &#x548C; inject &#x7ED1;&#x5B9A;&#x5E76;&#x4E0D;&#x662F;&#x53EF;&#x54CD;&#x5E94;&#x7684;&#x3002;&#x8FD9;&#x662F;&#x523B;&#x610F;&#x4E3A;&#x4E4B;&#x7684;&#x3002;&#x7136;&#x800C;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x4F20;&#x5165;&#x4E86;&#x4E00;&#x4E2A;&#x53EF;&#x76D1;&#x542C;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x90A3;&#x4E48;&#x5176;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x8FD8;&#x662F;&#x53EF;&#x54CD;&#x5E94;&#x7684;&#x3002;</p>
</blockquote>
<p>&#x6240;&#x4EE5;&#xFF0C;&#x4E0A;&#x9762; A.vue &#x7684; name &#x5982;&#x679C;&#x6539;&#x53D8;&#x4E86;&#xFF0C;B.vue &#x7684; this.name &#x662F;&#x4E0D;&#x4F1A;&#x6539;&#x53D8;&#x7684;&#xFF0C;&#x4ECD;&#x7136;&#x662F; foo&#x3002;</p>
<h2 id="&#x66FF;&#x4EE3;-vuex"><a name="&#x66FF;&#x4EE3;-vuex" class="anchor-navigation-ex-anchor" href="#&#x66FF;&#x4EE3;-vuex"><i class="fa fa-link" aria-hidden="true"></i></a>&#x66FF;&#x4EE3; Vuex</h2>
<p>&#x6211;&#x4EEC;&#x77E5;&#x9053;&#xFF0C;&#x5728;&#x505A; Vue &#x5927;&#x578B;&#x9879;&#x76EE;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; Vuex &#x505A;&#x72B6;&#x6001;&#x7BA1;&#x7406;&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x4E13;&#x4E3A; Vue.js &#x5F00;&#x53D1;&#x7684;&#x72B6;&#x6001;&#x7BA1;&#x7406;&#x6A21;&#x5F0F;&#xFF0C;&#x7528;&#x4E8E;&#x96C6;&#x4E2D;&#x5F0F;&#x5B58;&#x50A8;&#x7BA1;&#x7406;&#x5E94;&#x7528;&#x7684;&#x6240;&#x6709;&#x7EC4;&#x4EF6;&#x7684;&#x72B6;&#x6001;&#xFF0C;&#x5E76;&#x4EE5;&#x76F8;&#x5E94;&#x7684;&#x89C4;&#x5219;&#x4FDD;&#x8BC1;&#x72B6;&#x6001;&#x4EE5;&#x4E00;&#x79CD;&#x53EF;&#x9884;&#x6D4B;&#x7684;&#x65B9;&#x5F0F;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x3002;</p>
<p>&#x90A3;&#x4E86;&#x89E3;&#x4E86; provide / inject &#x7684;&#x7528;&#x6CD5;&#xFF0C;&#x4E0B;&#x9762;&#x6765;&#x770B;&#x600E;&#x6837;&#x66FF;&#x4EE3; Vuex&#x3002;&#x5F53;&#x7136;&#xFF0C;&#x6211;&#x4EEC;&#x7684;&#x76EE;&#x7684;&#x5E76;&#x4E0D;&#x662F;&#x4E3A;&#x4E86;&#x66FF;&#x4EE3; Vuex&#xFF0C;&#x5B83;&#x8FD8;&#x662F;&#x6709;&#x76F8;&#x5F53;&#x5927;&#x7684;&#x7528;&#x5904;&#xFF0C;&#x8FD9;&#x91CC;&#x53EA;&#x662F;&#x4ECB;&#x7ECD;&#x53E6;&#x4E00;&#x79CD;&#x53EF;&#x884C;&#x6027;&#x3002;</p>
<p>&#x4F7F;&#x7528; Vuex&#xFF0C;&#x6700;&#x4E3B;&#x8981;&#x7684;&#x76EE;&#x7684;&#x662F;&#x8DE8;&#x7EC4;&#x4EF6;&#x901A;&#x4FE1;&#x3001;&#x5168;&#x5C40;&#x6570;&#x636E;&#x7EF4;&#x62A4;&#x3001;&#x591A;&#x4EBA;&#x534F;&#x540C;&#x5F00;&#x53D1;&#x3002;&#x9700;&#x6C42;&#x6BD4;&#x5982;&#x6709;&#xFF1A;&#x7528;&#x6237;&#x7684;&#x767B;&#x5F55;&#x4FE1;&#x606F;&#x7EF4;&#x62A4;&#x3001;&#x901A;&#x77E5;&#x4FE1;&#x606F;&#x7EF4;&#x62A4;&#x7B49;&#x5168;&#x5C40;&#x7684;&#x72B6;&#x6001;&#x548C;&#x6570;&#x636E;&#x3002;</p>
<p>&#x4E00;&#x822C;&#x5728; webpack &#x4E2D;&#x4F7F;&#x7528; Vue.js&#xFF0C;&#x90FD;&#x4F1A;&#x6709;&#x4E00;&#x4E2A;&#x5165;&#x53E3;&#x6587;&#x4EF6; main.js&#xFF0C;&#x91CC;&#x9762;&#x901A;&#x5E38;&#x5BFC;&#x5165;&#x4E86; Vue&#x3001;VueRouter&#x7B49;&#x5E93;&#xFF0C;&#x901A;&#x5E38;&#x4E5F;&#x4F1A;&#x5BFC;&#x5165;&#x4E00;&#x4E2A;&#x5165;&#x53E3;&#x7EC4;&#x4EF6; app.vue &#x4F5C;&#x4E3A;&#x6839;&#x7EC4;&#x4EF6;&#x3002;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684; app.vue &#x53EF;&#x80FD;&#x53EA;&#x6709;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre class="language-"><code class="lang-js"><span class="token operator">&lt;</span>template<span class="token operator">&gt;</span>
  <span class="token operator">&lt;</span>div<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>router<span class="token operator">-</span>view<span class="token operator">&gt;</span><span class="token operator">&lt;</span><span class="token operator">/</span>router<span class="token operator">-</span>view<span class="token operator">&gt;</span>
  <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>template<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span>script<span class="token operator">&gt;</span>
  <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>

  <span class="token punctuation">}</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">&gt;</span>
</code></pre>
<p>&#x4F7F;&#x7528; provide / inject &#x66FF;&#x4EE3; Vuex&#xFF0C;&#x5C31;&#x662F;&#x5728;&#x8FD9;&#x4E2A; app.vue &#x6587;&#x4EF6;&#x4E0A;&#x505A;&#x6587;&#x7AE0;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x628A; app.vue &#x7406;&#x89E3;&#x4E3A;&#x4E00;&#x4E2A;&#x6700;&#x5916;&#x5C42;&#x7684;&#x6839;&#x7EC4;&#x4EF6;&#xFF0C;&#x7528;&#x6765;&#x5B58;&#x50A8;&#x6240;&#x6709;&#x9700;&#x8981;&#x7684;&#x5168;&#x5C40;&#x6570;&#x636E;&#x548C;&#x72B6;&#x6001;&#xFF0C;&#x751A;&#x81F3;&#x662F;&#x8BA1;&#x7B97;&#x5C5E;&#x6027;&#xFF08;computed&#xFF09;&#x3001;&#x65B9;&#x6CD5;&#xFF08;methods&#xFF09;&#x7B49;&#x3002;&#x56E0;&#x4E3A;&#x4F60;&#x7684;&#x9879;&#x76EE;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x7EC4;&#x4EF6;&#xFF08;&#x5305;&#x542B;&#x8DEF;&#x7531;&#xFF09;&#xFF0C;&#x5B83;&#x7684;&#x7236;&#x7EC4;&#x4EF6;&#xFF08;&#x6216;&#x6839;&#x7EC4;&#x4EF6;&#xFF09;&#x90FD;&#x662F; app.vue&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x628A;&#x6574;&#x4E2A; app.vue &#x5B9E;&#x4F8B;&#x901A;&#x8FC7; provide &#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#x3002;</p>
<pre class="language-"><code class="lang-js"><span class="token operator">&lt;</span>template<span class="token operator">&gt;</span>
  <span class="token operator">&lt;</span>div<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>router<span class="token operator">-</span>view<span class="token operator">&gt;</span><span class="token operator">&lt;</span><span class="token operator">/</span>router<span class="token operator">-</span>view<span class="token operator">&gt;</span>
  <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>template<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span>script<span class="token operator">&gt;</span>
  <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    <span class="token function">provide</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token punctuation">{</span>
        app<span class="token punctuation">:</span> <span class="token keyword">this</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">&gt;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#xFF0C;&#x6211;&#x4EEC;&#x628A;&#x6574;&#x4E2A; app.vue &#x7684;&#x5B9E;&#x4F8B; this &#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#xFF0C;&#x547D;&#x540D;&#x4E3A; app&#xFF08;&#x8FD9;&#x4E2A;&#x540D;&#x5B57;&#x53EF;&#x4EE5;&#x81EA;&#x5B9A;&#x4E49;&#xFF0C;&#x63A8;&#x8350;&#x4F7F;&#x7528; app&#xFF0C;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x540D;&#x5B57;&#x540E;&#xFF0C;&#x5B50;&#x7EC4;&#x4EF6;&#x4E0D;&#x80FD;&#x518D;&#x4F7F;&#x7528;&#x5B83;&#x4F5C;&#x4E3A;&#x5C40;&#x90E8;&#x5C5E;&#x6027;&#xFF09;&#x3002;&#x63A5;&#x4E0B;&#x6765;&#xFF0C;&#x4EFB;&#x4F55;&#x7EC4;&#x4EF6;&#xFF08;&#x6216;&#x8DEF;&#x7531;&#xFF09;&#x53EA;&#x8981;&#x901A;&#x8FC7; inject &#x6CE8;&#x5165; app.vue &#x7684; app &#x7684;&#x8BDD;&#xFF0C;&#x90FD;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x901A;&#x8FC7; this.app.xxx &#x6765;&#x8BBF;&#x95EE; app.vue &#x7684; data&#x3001;computed&#x3001;methods &#x7B49;&#x5185;&#x5BB9;&#x3002;</p>
<p>app.vue &#x662F;&#x6574;&#x4E2A;&#x9879;&#x76EE;&#x7B2C;&#x4E00;&#x4E2A;&#x88AB;&#x6E32;&#x67D3;&#x7684;&#x7EC4;&#x4EF6;&#xFF0C;&#x800C;&#x4E14;&#x53EA;&#x4F1A;&#x6E32;&#x67D3;&#x4E00;&#x6B21;&#xFF08;&#x5373;&#x4F7F;&#x5207;&#x6362;&#x8DEF;&#x7531;&#xFF0C;app.vue &#x4E5F;&#x4E0D;&#x4F1A;&#x88AB;&#x518D;&#x6B21;&#x6E32;&#x67D3;&#xFF09;&#xFF0C;&#x5229;&#x7528;&#x8FD9;&#x4E2A;&#x7279;&#x6027;&#xFF0C;&#x5F88;&#x9002;&#x5408;&#x505A;&#x4E00;&#x6B21;&#x6027;&#x5168;&#x5C40;&#x7684;&#x72B6;&#x6001;&#x6570;&#x636E;&#x7BA1;&#x7406;&#xFF0C;&#x4F8B;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x7528;&#x6237;&#x7684;&#x767B;&#x5F55;&#x4FE1;&#x606F;&#x4FDD;&#x5B58;&#x8D77;&#x6765;&#xFF1A;</p>
<pre class="language-"><code class="lang-js"><span class="token operator">&lt;</span>script<span class="token operator">&gt;</span>
  <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    <span class="token function">provide</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token punctuation">{</span>
        app<span class="token punctuation">:</span> <span class="token keyword">this</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function">data</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token punctuation">{</span>
        userInfo<span class="token punctuation">:</span> <span class="token keyword">null</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    methods<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      <span class="token function">getUserInfo</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// &#x8FD9;&#x91CC;&#x901A;&#x8FC7; ajax &#x83B7;&#x53D6;&#x7528;&#x6237;&#x4FE1;&#x606F;&#x540E;&#xFF0C;&#x8D4B;&#x503C;&#x7ED9; this.userInfo&#xFF0C;&#x4EE5;&#x4E0B;&#x4E3A;&#x4F2A;&#x4EE3;&#x7801;</span>
        $<span class="token punctuation">.</span><span class="token function">ajax</span><span class="token punctuation">(</span><span class="token string">&apos;/user/info&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">data</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
          <span class="token keyword">this</span><span class="token punctuation">.</span>userInfo <span class="token operator">=</span> data<span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function">mounted</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getUserInfo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">&gt;</span>
</code></pre>
<p>&#x8FD9;&#x6837;&#xFF0C;&#x4EFB;&#x4F55;&#x9875;&#x9762;&#x6216;&#x7EC4;&#x4EF6;&#xFF0C;&#x53EA;&#x8981;&#x901A;&#x8FC7; inject &#x6CE8;&#x5165; app &#x540E;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8BBF;&#x95EE; userInfo &#x7684;&#x6570;&#x636E;&#x4E86;&#xFF0C;&#x6BD4;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-js"><span class="token operator">&lt;</span>template<span class="token operator">&gt;</span>
  <span class="token operator">&lt;</span>div<span class="token operator">&gt;</span>
    <span class="token punctuation">{</span><span class="token punctuation">{</span> app<span class="token punctuation">.</span>userInfo <span class="token punctuation">}</span><span class="token punctuation">}</span>
  <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>template<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span>script<span class="token operator">&gt;</span>
  <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    inject<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&apos;app&apos;</span><span class="token punctuation">]</span>
  <span class="token punctuation">}</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">&gt;</span>
</code></pre>
<p>&#x662F;&#x4E0D;&#x662F;&#x5F88;&#x7B80;&#x5355;&#x5462;&#x3002;&#x9664;&#x4E86;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x6570;&#x636E;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x8C03;&#x7528;&#x65B9;&#x6CD5;&#x3002;&#x6BD4;&#x5982;&#x5728;&#x67D0;&#x4E2A;&#x9875;&#x9762;&#x91CC;&#xFF0C;&#x4FEE;&#x6539;&#x4E86;&#x4E2A;&#x4EBA;&#x8D44;&#x6599;&#xFF0C;&#x8FD9;&#x65F6;&#x4E00;&#x5F00;&#x59CB;&#x5728; app.vue &#x91CC;&#x83B7;&#x53D6;&#x7684; userInfo &#x5DF2;&#x7ECF;&#x4E0D;&#x662F;&#x6700;&#x65B0;&#x7684;&#x4E86;&#xFF0C;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x83B7;&#x53D6;&#x3002;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#x4F7F;&#x7528;&#xFF1A;</p>
<pre class="language-"><code class="lang-js"><span class="token operator">&lt;</span>template<span class="token operator">&gt;</span>
  <span class="token operator">&lt;</span>div<span class="token operator">&gt;</span>
    <span class="token punctuation">{</span><span class="token punctuation">{</span> app<span class="token punctuation">.</span>userInfo <span class="token punctuation">}</span><span class="token punctuation">}</span>
  <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>template<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span>script<span class="token operator">&gt;</span>
  <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    inject<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&apos;app&apos;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
    methods<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      <span class="token function">changeUserInfo</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// &#x8FD9;&#x91CC;&#x4FEE;&#x6539;&#x5B8C;&#x7528;&#x6237;&#x6570;&#x636E;&#x540E;&#xFF0C;&#x901A;&#x77E5; app.vue &#x66F4;&#x65B0;&#xFF0C;&#x4EE5;&#x4E0B;&#x4E3A;&#x4F2A;&#x4EE3;&#x7801;</span>
        $<span class="token punctuation">.</span><span class="token function">ajax</span><span class="token punctuation">(</span><span class="token string">&apos;/user/update&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
          <span class="token comment">// &#x76F4;&#x63A5;&#x901A;&#x8FC7; this.app &#x5C31;&#x53EF;&#x4EE5;&#x8C03;&#x7528; app.vue &#x91CC;&#x7684;&#x65B9;&#x6CD5;</span>
          <span class="token keyword">this</span><span class="token punctuation">.</span>app<span class="token punctuation">.</span><span class="token function">getUserInfo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">&gt;</span>
</code></pre>
<p>&#x540C;&#x6837;&#x975E;&#x5E38;&#x7B80;&#x5355;&#x3002;&#x53EA;&#x8981;&#x7406;&#x89E3;&#x4E86; this.app &#x662F;&#x76F4;&#x63A5;&#x83B7;&#x53D6;&#x6574;&#x4E2A; app.vue &#x7684;&#x5B9E;&#x4F8B;&#x540E;&#xFF0C;&#x4F7F;&#x7528;&#x8D77;&#x6765;&#x5C31;&#x5F97;&#x5FC3;&#x5E94;&#x624B;&#x4E86;&#x3002;&#x60F3;&#x4E00;&#x60F3;&#xFF0C;&#x914D;&#x7F6E;&#x590D;&#x6742;&#x7684; Vuex &#x7684;&#x5168;&#x90E8;&#x529F;&#x80FD;&#xFF0C;&#x73B0;&#x5728;&#x662F;&#x4E0D;&#x662F;&#x90FD;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; provide / inject &#x6765;&#x5B9E;&#x73B0;&#x4E86;&#x5462;&#xFF1F;</p>
<h2 id="&#x4F7F;&#x7528;mixin"><a name="&#x4F7F;&#x7528;mixin" class="anchor-navigation-ex-anchor" href="#&#x4F7F;&#x7528;mixin"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4F7F;&#x7528;mixin</h2>
<p>&#x53EF;&#x4EE5;&#x628A;&#x4E0A;&#x9762;&#x7684;app.vue&#x4E2D;&#x7684;&#x76F8;&#x5173;&#x4EE3;&#x7801; &#x5199;&#x5165;mixin &#x4FBF;&#x4E8E;&#x7EF4;&#x62A4;</p>
<pre class="language-"><code class="lang-js"><span class="token operator">&lt;</span>script<span class="token operator">&gt;</span>
  <span class="token keyword">import</span> mixins_user <span class="token keyword">from</span> <span class="token string">&apos;../mixins/user.js&apos;</span><span class="token punctuation">;</span>

  <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    mixins<span class="token punctuation">:</span> <span class="token punctuation">[</span>mixins_user<span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token function">data</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token punctuation">{</span>

      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">&gt;</span>
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; YoungGary 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2021-09-09 22:08:17
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: Vue组件精讲">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="2.html" class="navigation navigation-next " aria-label="Next page: 2.手动实现broadcast和dispatch方法">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1.provide/inject","level":"1.4.1","depth":2,"next":{"title":"2.手动实现broadcast和dispatch方法","level":"1.4.2","depth":2,"path":"vue/2.md","ref":"vue/2.md","articles":[]},"previous":{"title":"Vue组件精讲","level":"1.4","depth":1,"path":"vue/README.md","ref":"vue/README.md","articles":[{"title":"1.provide/inject","level":"1.4.1","depth":2,"path":"vue/1.md","ref":"vue/1.md","articles":[]},{"title":"2.手动实现broadcast和dispatch方法","level":"1.4.2","depth":2,"path":"vue/2.md","ref":"vue/2.md","articles":[]},{"title":"3.自己动手实现带校验的Form表单组件","level":"1.4.3","depth":2,"path":"js/form.md","ref":"js/form.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["theme-comscore","prism","-highlight","copy-code-button","search-pro","-search","-lunr","expandable-chapters","splitter","-sharing","tbfed-pagefooter","anchor-navigation-ex"],"styles":{},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy YoungGary 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prismjs/themes/prism-solarizedlight.css"],"lang":{"shell":"bash"}},"splitter":{},"search-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"theme-comscore":{},"copy-code-button":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"Gary","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Gary的小窝","language":"zh-hans","gitbook":"*","description":"Gary的小窝. 里面包含了个人撰写的技术文章"},"file":{"path":"vue/1.md","mtime":"2021-09-09T14:08:17.741Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-09-09T14:10:10.930Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

